# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=aspell
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.60.7
pkgrel=1
pkgdesc="A spell checker designed to eventually replace Ispell (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="http://aspell.net/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
            "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-gettext")
options=('strip' 'staticlibs')
source=("https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.gz"
        0001-use-namespace.mingw.patch
        0002-printf.mingw.patch
        0003-no-undefined-on.mingw.patch
        0004-reloc.mingw.patch
        0005-w32-home.all.patch
        0006-abort.mingw.patch
        0007-fix-including-langinfo.patch)
sha256sums=('5ca8fc8cb0370cc6c9eb5b64c6d1bc5d57b3750dbf17887726c3407d833b70e4'
            '903c798d1afa40b4e36ec0d4c1b82a967d217507f03742c3c480568cc527e429'
            'ec5c71c96f9e8e299a818aae930a766832f52c431f44a7d42b0c69ad3cb18ffe'
            'b2c36f72abae7b31bf988fb9466543f0836aecbf84abcce09ca7c04c5e7fd4ff'
            '458bc2d9b2193fb6c40023d4656bee603ea5996ea55ba4b86ae337ca3fed2f2d'
            'c0cd30738e30de948b4cfc33f2b8672c7b57410f6c5bd04358fa9cfba29ab9c9'
            '34155f49b3cddd1e02e0d244cba286d97dab229088148261c2b5c499664ba299'
            '8ff2cfc11963d0738c435a27c42e2f28dabf473270310f98ef6252a9707d4501')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-use-namespace.mingw.patch
  patch -p1 -i ${srcdir}/0002-printf.mingw.patch
  patch -p1 -i ${srcdir}/0003-no-undefined-on.mingw.patch
  patch -p1 -i ${srcdir}/0004-reloc.mingw.patch
  patch -p1 -i ${srcdir}/0005-w32-home.all.patch
  patch -p1 -i ${srcdir}/0006-abort.mingw.patch
  patch -p1 -i ${srcdir}/0007-fix-including-langinfo.patch

  autoreconf -fi
}

build() {
  CPPFLAGS+=" -DENABLE_W32_PREFIX=1"
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  cp -rf ${_realname}-${pkgver} build-${MINGW_CHOST}
  cd "${srcdir}/build-${MINGW_CHOST}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --disable-curses

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="${pkgdir}" install
}
